package com.jianying.day03;

import com.jianying.beans.WaterSensor;
import com.jianying.func.WaterSensorMapFunction;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.KeyedStream;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * ClassName: Flink09_Trans_Map
 * Package: com.atguigu.day03
 * Description:
 *
 * @Author: tubage
 * @Create: 2024/4/1 15:05
 * @Version: 1.0
 */
public class Flink13_Trans_Max_MaxBy {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        DataStreamSource<String> socketDS = env.socketTextStream("localhost", 8888);

        SingleOutputStreamOperator<WaterSensor> mapDS = socketDS.map(
                new WaterSensorMapFunction()
        );

        // 分组流 键控流
        KeyedStream<WaterSensor, String> keyByDS = mapDS.keyBy(waterSensor -> waterSensor.id);

//        SingleOutputStreamOperator<WaterSensor> maxDS = keyByDS.max("vc");
        SingleOutputStreamOperator<WaterSensor> maxByDS = keyByDS.maxBy("vc");
        maxByDS.print();


        env.execute();
    }
}
